package cn.tedu.charging.cost.dao.repository.impl;

import cn.tedu.charging.cost.dao.repository.CostRuleCacheRepository;
import cn.tedu.charging.cost.pojo.po.ChargingCostRulePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CostRuleCacheRepositoryImpl implements CostRuleCacheRepository {

    @Autowired
    private RedisTemplate<String,List<ChargingCostRulePO>> redisTemplate;

    @Override
    public List<ChargingCostRulePO> getCostRulesFromRedisByStationId(Integer stationId) {
        ValueOperations<String, List<ChargingCostRulePO>> stringOperations = redisTemplate.opsForValue();
        String key = "COST_RULE_KEY_" + stationId;
        return stringOperations.get(key);
    }

    @Override
    public void saveCostRules2Redis(Integer stationId, List<ChargingCostRulePO> dbCostRules) {
        ValueOperations<String, List<ChargingCostRulePO>> stringOperations = redisTemplate.opsForValue();
        String key = "COST_RULE_KEY_" + stationId;
        stringOperations.set(key,dbCostRules);
    }
}
